﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using HRM.Models;
using System.IO;
namespace HRM.Controllers
{
    public class BKController : Controller
    {
        //
        // GET: /BK/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Backup()
        {            
            String backupDIR = "backup";
            var filePath = System.Web.HttpContext.Current.Server.MapPath("~/" + backupDIR);
            if (!System.IO.Directory.Exists(filePath))
            {
                System.IO.Directory.CreateDirectory(filePath);
            }
            filePath = filePath + "\\" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".Bak";
            var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
            var objs = new WebData().Users.Backup(filePath,"NS");
            var jsonResult = new ContentResult
            {
                Content = JsonConvert.SerializeObject(objs, settings),
                ContentType = "application/json"
            };
            return jsonResult;
        }
    }
}
